﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Data;
using System.Data.SqlClient;
using Support.DTO;

namespace DataAccess
{
    public class AbdomenDAL : BaseSQLDAL
    {
        public int GuardarAbdomen(AbdomenDTO abdomen)
        {
            try
            {
                CreateCommand("Abdomen_Guardar", true);
                AddCmdParameter("@Inspeccion", string.IsNullOrEmpty(abdomen.Inspeccion) ? "" : abdomen.Inspeccion, ParameterDirection.Input);
                AddCmdParameter("@Palpacion", string.IsNullOrEmpty(abdomen.Palpacion) ? "" : abdomen.Palpacion, ParameterDirection.Input);
                AddCmdParameter("@Auscultacion", string.IsNullOrEmpty(abdomen.Auscultacion) ? "" : abdomen.Auscultacion, ParameterDirection.Input);
                AddCmdParameter("@HistoriaId", abdomen.HistoriaId, ParameterDirection.Input);

                ExecuteReader();
                Read();

                return Convert.ToInt32(GetOutResult("abdomen_id"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }

        public void Modificar(AbdomenDTO abdomen)
        {
            try
            {
                CreateCommand("Abdomen_Modificar", true);
                AddCmdParameter("@Inspeccion", string.IsNullOrEmpty(abdomen.Inspeccion) ? "" : abdomen.Inspeccion, ParameterDirection.Input);
                AddCmdParameter("@Palpacion", string.IsNullOrEmpty(abdomen.Palpacion) ? "" : abdomen.Palpacion, ParameterDirection.Input);
                AddCmdParameter("@Auscultacion", string.IsNullOrEmpty(abdomen.Auscultacion) ? "" : abdomen.Auscultacion, ParameterDirection.Input);
                AddCmdParameter("@HistoriaId", abdomen.HistoriaId, ParameterDirection.Input);

                ExecuteReader();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }



        public void Eliminar(int historiaId)
        {
            try
            {
                CreateCommand("Abdomen_Eliminar", true);
                AddCmdParameter("@HistoriaId", historiaId, ParameterDirection.Input);
                
                ExecuteReader();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DisposeCommand();
                //DisposeDataReader();
                CloseConnection();
            }
        }
    }
}
